package com.naicheng.ivote.views;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.naicheng.ivote.R;
import com.naicheng.ivote.engin.BaseFragment;
import com.naicheng.ivote.engin.BaseFragmentActivity;
import com.naicheng.ivote.views.fragments.FindNewFragment;
import com.naicheng.ivote.views.fragments.FindNowFragment;
import com.naicheng.ivote.views.fragments.FindResultFragment;

public class FindJingCaiActivity extends BaseFragmentActivity {
	
	private RadioGroup rg_title;
	
	private FragmentTransaction ft ;
	private FindNewFragment findNewFragment;
	private FindNowFragment findNowFragment;
	private FindResultFragment findResultFragment;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.find_jingcai_activity);
		
		rg_title = getView(R.id.rg_title);
		getView(R.id.tv_back).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		findNewFragment = new FindNewFragment();
//		ft.add(R.id.fl_find_container,findNewFragment, findNewFragment.TAG);
		findNowFragment = new FindNowFragment();
//		ft.add(R.id.fl_find_container,findNowFragment, findNowFragment.TAG);
		findResultFragment = new FindResultFragment();
//		ft.add(R.id.fl_find_container,findResultFragment, findResultFragment.TAG);
//		ft.commit();
		
		rg_title.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				ft = getSupportFragmentManager().beginTransaction();
				switch (group.getCheckedRadioButtonId()) {
				case R.id.rb_new:
					ft.replace(R.id.fl_find_container,findNewFragment, findNewFragment.TAG);
					ft.commit();
					break;
				case R.id.rb_now:
					ft.replace(R.id.fl_find_container,findNowFragment, findNowFragment.TAG);
					ft.commit();
					break;
				case R.id.rb_result:
					ft.replace(R.id.fl_find_container,findResultFragment, findResultFragment.TAG);
					ft.commit();
					break;
				default:
					break;
				}
			}
		});
		rg_title.check(R.id.rb_new);
	}
}
